﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IGGCore;
using IGGWindowApp.Controls;
using IGGWindowApp.Data;

namespace IGGWindowApp.Panels
{
    public partial class PanelNews : UserControl
    {
        // EVENTS
        public delegate void ItemSelectedHandler(string item);
        public event ItemSelectedHandler ItemSelected;

        int columnA = 0;
        int columnB = 0;

        public PanelNews()
        {
            InitializeComponent();
        }

        private void panelTitle_ItemSelected(string item)
        {
            ItemSelected(item);
        }

        public void SetData(List<News> news)
        {
            columnA = 0;
            columnB = 0;
            lblLetter.Text = news[0].Content[0].ToString();
            lblLetter.Visible = true;

            //lblNews1.Text = news[1].Title;
            txtNews1.Text = news[0].Content.Substring(1);
            //lblNews1.Visible = true;
            txtNews1.Visible = true;

            lblNews3.Text = news[1].Title;
            txtNews3.Text = news[1].Content;
            lblNews3.Visible = true;
            txtNews3.Visible = true;

            lblNews4.Text = news[2].Title;
            txtNews4.Text = news[2].Content;
            lblNews4.Visible = true;
            txtNews4.Visible = true;

            lblNews5.Text = news[3].Title;
            txtNews5.Text = news[3].Content;
            lblNews5.Visible = true;
            txtNews5.Visible = true;

            lblNews6.Text = news[4].Title;
            txtNews6.Text = news[4].Content;
            lblNews6.Visible = true;
            txtNews6.Visible = true;

            lblNews7.Text = news[5].Title;
            txtNews7.Text = news[5].Content;
            lblNews7.Visible = true;
            txtNews7.Visible = true;

            lblNews8.Text = news[6].Title;
            txtNews8.Text = news[6].Content;
            lblNews8.Visible = true;
            txtNews8.Visible = true;

            lblNews9.Text = news[7].Title;
            txtNews9.Text = news[7].Content;
            lblNews9.Visible = true;
            txtNews9.Visible = true;

            lblNews10.Text = news[8].Title;
            txtNews10.Text = news[8].Content;
            lblNews10.Visible = true;
            txtNews10.Visible = true;

            //lblNews11.Text = news[10].Title;
            //txtNews11.Text = news[10].Content;
            //lblNews11.Visible = true;
            //txtNews11.Visible = true;

            //lblNews12.Text = news[11].Title;
            //txtNews12.Text = news[11].Content;
            //lblNews12.Visible = true;
            //txtNews12.Visible = true;
        }

        private void txtNews1_ContentsResized(object sender, ContentsResizedEventArgs e)
        {
            AdvRichTextBox tb = ((AdvRichTextBox)sender);
            tb.Height = e.NewRectangle.Height + 11;

            if (tb.Tag != null)
            {
                if (tb.Tag.ToString() == "b")
                {
                    columnB += e.NewRectangle.Height + 11;
                    if (columnB > 1900)
                    {
                        lblNews12.Visible = false;
                        txtNews12.Visible = false;
                    }
                }
                else if (tb.Tag.ToString() == "a")
                {
                    columnA += e.NewRectangle.Height + 11;
                    if (columnB > 1900)
                    {
                        lblNews11.Visible = false;
                        txtNews11.Visible = false;
                    }
                }
            }

        }

        private void Title_ContentsResized(object sender, ContentsResizedEventArgs e)
        {
            AdvRichTextBox tb = ((AdvRichTextBox)sender);
            ((AdvRichTextBox)sender).Height = e.NewRectangle.Height + 5;
            if (tb.Tag != null)
            {
                if (tb.Tag.ToString() == "b")
                {
                    columnB += e.NewRectangle.Height + 9;
                }
                else if (tb.Tag.ToString() == "a")
                {
                    columnA += e.NewRectangle.Height + 9;
                }
            }
        }

        private void lblLetter_TextChanged(object sender, EventArgs e)
        {
            SizeF size = lblLetter.CreateGraphics().MeasureString(lblLetter.Text, lblLetter.Font);
            lblLetter.Width = (int)size.Width;
            panelLetter.Width = lblLetter.Width-8;
            panelLetter.Refresh();
        }

    }
}
